/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CobroFactura.java
 *
 * Created on 31-ago-2011, 11:34:59
 */

package proyectoempresa.igu;

import Reportes.IniciarReporte;
import java.util.logging.Level;
import java.util.logging.Logger;
import proyectoempresa.DAO.FacturaDao;
import proyectoempresa.modelo.Factura;

/**
 *
 * @author Diego
 */
public class CobroFactura extends javax.swing.JDialog {

    /** Creates new form CobroFactura */
    Factura factura;
    String valorTotal;
    String id_DCliente;
      IniciarReporte reporte;
      FacturaDao facd;
    public CobroFactura(java.awt.Frame parent, boolean modal, Factura factura, String valorTota, String id_cliente, FacturaDao fd) {
        super(parent, modal);
        this.factura=factura;
        this.valorTotal=valorTota;
        this.id_DCliente=id_cliente;
        this.facd=fd;
        initComponents();
        txtValorTotal.setText(valorTotal);
         reporte = new IniciarReporte();
         setLocationRelativeTo(null);
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        panel1 = new org.edisoncor.gui.panel.Panel();
        txtValorTotal = new javax.swing.JTextField();
        buttonColoredAction1 = new org.edisoncor.gui.button.ButtonColoredAction();
        buttonColoredAction2 = new org.edisoncor.gui.button.ButtonColoredAction();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtCambio = new javax.swing.JTextField();
        txtEfectivo = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setUndecorated(true);

        panel1.setForeground(new java.awt.Color(102, 102, 255));
        panel1.setColorPrimario(new java.awt.Color(255, 153, 153));
        panel1.setColorSecundario(new java.awt.Color(153, 0, 204));
        panel1.setName("panel1"); // NOI18N

        txtValorTotal.setBackground(new java.awt.Color(0, 0, 0));
        txtValorTotal.setEditable(false);
        txtValorTotal.setFont(new java.awt.Font("Castellar", 3, 48)); // NOI18N
        txtValorTotal.setForeground(new java.awt.Color(255, 255, 255));
        txtValorTotal.setCaretColor(new java.awt.Color(0, 0, 255));
        txtValorTotal.setName("txtValorTotal"); // NOI18N

        buttonColoredAction1.setText("SALIR");
        buttonColoredAction1.setName("buttonColoredAction1"); // NOI18N
        buttonColoredAction1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonColoredAction1ActionPerformed(evt);
            }
        });

        buttonColoredAction2.setText("IMPRIMIR");
        buttonColoredAction2.setName("buttonColoredAction2"); // NOI18N
        buttonColoredAction2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonColoredAction2ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Times New Roman", 3, 14));
        jLabel1.setText("INGRESE EFECTIVO:");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setFont(new java.awt.Font("Times New Roman", 3, 14));
        jLabel2.setText("CAMBIO A DEVOLVER:");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Times New Roman", 3, 18)); // NOI18N
        jLabel3.setText("VALOR TOTAL:");
        jLabel3.setName("jLabel3"); // NOI18N

        txtCambio.setBackground(new java.awt.Color(0, 0, 0));
        txtCambio.setEditable(false);
        txtCambio.setFont(new java.awt.Font("Castellar", 3, 48)); // NOI18N
        txtCambio.setForeground(new java.awt.Color(255, 255, 255));
        txtCambio.setCaretColor(new java.awt.Color(0, 0, 255));
        txtCambio.setName("txtCambio"); // NOI18N

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${factura.cambio}"), txtCambio, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtCambio.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtCambioFocusGained(evt);
            }
        });

        txtEfectivo.setBackground(new java.awt.Color(0, 0, 0));
        txtEfectivo.setFont(new java.awt.Font("Castellar", 3, 48));
        txtEfectivo.setForeground(new java.awt.Color(255, 255, 255));
        txtEfectivo.setCaretColor(new java.awt.Color(0, 0, 255));
        txtEfectivo.setName("txtEfectivo"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${factura.efectivo}"), txtEfectivo, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtEfectivo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtEfectivoMouseClicked(evt);
            }
        });
        txtEfectivo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtEfectivoKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout panel1Layout = new javax.swing.GroupLayout(panel1);
        panel1.setLayout(panel1Layout);
        panel1Layout.setHorizontalGroup(
            panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel1Layout.createSequentialGroup()
                .addGap(66, 66, 66)
                .addComponent(jLabel2)
                .addContainerGap(45, Short.MAX_VALUE))
            .addGroup(panel1Layout.createSequentialGroup()
                .addGap(74, 74, 74)
                .addComponent(jLabel1)
                .addContainerGap(50, Short.MAX_VALUE))
            .addGroup(panel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(buttonColoredAction2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonColoredAction1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(12, Short.MAX_VALUE))
            .addComponent(txtValorTotal, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
            .addComponent(txtCambio, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
            .addComponent(txtEfectivo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
            .addGroup(panel1Layout.createSequentialGroup()
                .addGap(69, 69, 69)
                .addComponent(jLabel3)
                .addContainerGap(62, Short.MAX_VALUE))
        );
        panel1Layout.setVerticalGroup(
            panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtValorTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtEfectivo, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtCambio, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonColoredAction2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonColoredAction1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtEfectivoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtEfectivoMouseClicked
        // TODO add your handling code here:
               if (txtEfectivo.getText().equals("")||txtEfectivo.getText().equals(" ")||txtEfectivo.getText().equals("   ")) {
             txtEfectivo.setText("0.0");
             txtCambio.setText("0.0");
        }else{
                   if (txtEfectivo.getText().equals("0.0")) {
                       txtCambio.setText("0.0");
                   }else{
          txtCambio.setText(String.valueOf(factura.obtenercambio(Double.valueOf(txtEfectivo.getText()))));
                   }
        }
    }//GEN-LAST:event_txtEfectivoMouseClicked

    private void buttonColoredAction1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonColoredAction1ActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_buttonColoredAction1ActionPerformed

    private void buttonColoredAction2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonColoredAction2ActionPerformed
        try {
            // TODO add your handling code here:
            facd.update();
            reporte.ejecutarReporte(id_DCliente);
            dispose();
        } catch (Exception ex) {
            Logger.getLogger(CobroFactura.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_buttonColoredAction2ActionPerformed

    private void txtCambioFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCambioFocusGained
        // TODO add your handling code here:
     if (txtEfectivo.getText().equals("")||txtEfectivo.getText().equals(" ")||txtEfectivo.getText().equals("   ")) {
             txtEfectivo.setText("0.0");
             txtCambio.setText("0.0");
        }else{
                   if (txtEfectivo.getText().equals("0.0")) {
                       txtCambio.setText("0.0");
                   }else{
          txtCambio.setText(String.valueOf(factura.obtenercambio(Double.valueOf(txtEfectivo.getText()))));
                   }
        }
        
    }//GEN-LAST:event_txtCambioFocusGained

    private void txtEfectivoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtEfectivoKeyTyped
        // TODO add your handling code here:
         char a = evt.getKeyChar();
        if (Character.isDigit(a) || a == '.') {
        } else {
            evt.consume();
        }
    }//GEN-LAST:event_txtEfectivoKeyTyped

    /**
    * @param args the command line arguments
    */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                CobroFactura dialog = new CobroFactura(new javax.swing.JFrame(), true);
//                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.edisoncor.gui.button.ButtonColoredAction buttonColoredAction1;
    private org.edisoncor.gui.button.ButtonColoredAction buttonColoredAction2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private org.edisoncor.gui.panel.Panel panel1;
    private javax.swing.JTextField txtCambio;
    private javax.swing.JTextField txtEfectivo;
    private javax.swing.JTextField txtValorTotal;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    public Factura getFactura() {
        return factura;
    }

    public void setFactura(Factura factura) {
        this.factura = factura;
    }

}
